package com.example.springboot.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {
    public Integer code;
    public String msg;
    public Object result;

    public static Result success(){
        return new Result(200, "success", null);
    }
    public static Result success(Object data){
        return new Result(200, "success", data);
    }
    public static Result error(Integer code){
        String msg = "error";

        if(code == 401){
            msg = "客户端错误";
        }
        if(code == 500){
            msg = "服务端错误";
        }

        return new Result(code, msg, null);
    }
}
